package org.jeecg.modules.crm.service.impl;

import org.jeecg.modules.crm.entity.Agent;
import org.jeecg.modules.crm.entity.SubSalesScheme;
import org.jeecg.modules.crm.entity.AccumulatedSales;
import org.jeecg.modules.crm.entity.AgentProjectScheme;
import org.jeecg.modules.crm.entity.AgentSpecialOverriding;
import org.jeecg.modules.crm.entity.AgentPromote;
import org.jeecg.modules.crm.entity.WithholdingTax;
import org.jeecg.modules.crm.mapper.SubSalesSchemeMapper;
import org.jeecg.modules.crm.mapper.AccumulatedSalesMapper;
import org.jeecg.modules.crm.mapper.AgentProjectSchemeMapper;
import org.jeecg.modules.crm.mapper.AgentSpecialOverridingMapper;
import org.jeecg.modules.crm.mapper.AgentPromoteMapper;
import org.jeecg.modules.crm.mapper.WithholdingTaxMapper;
import org.jeecg.modules.crm.mapper.AgentMapper;
import org.jeecg.modules.crm.service.IAgentService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.io.Serializable;
import java.util.List;
import java.util.Collection;

/**
 * @Description: Agent
 * @Author: jeecg-boot
 * @Date:   2025-04-13
 * @Version: V1.0
 */
@Service
public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements IAgentService {

	@Autowired
	private AgentMapper agentMapper;
	@Autowired
	private SubSalesSchemeMapper subSalesSchemeMapper;
	@Autowired
	private AccumulatedSalesMapper accumulatedSalesMapper;
	@Autowired
	private AgentProjectSchemeMapper agentProjectSchemeMapper;
	@Autowired
	private AgentSpecialOverridingMapper agentSpecialOverridingMapper;
	@Autowired
	private AgentPromoteMapper agentPromoteMapper;
	@Autowired
	private WithholdingTaxMapper withholdingTaxMapper;
	
	@Override
	@Transactional(rollbackFor = Exception.class)
	public void delMain(String id) {
		subSalesSchemeMapper.deleteByMainId(id);
		accumulatedSalesMapper.deleteByMainId(id);
		agentProjectSchemeMapper.deleteByMainId(id);
		agentSpecialOverridingMapper.deleteByMainId(id);
		agentPromoteMapper.deleteByMainId(id);
		withholdingTaxMapper.deleteByMainId(id);
		agentMapper.deleteById(id);
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void delBatchMain(Collection<? extends Serializable> idList) {
		for(Serializable id:idList) {
			subSalesSchemeMapper.deleteByMainId(id.toString());
			accumulatedSalesMapper.deleteByMainId(id.toString());
			agentProjectSchemeMapper.deleteByMainId(id.toString());
			agentSpecialOverridingMapper.deleteByMainId(id.toString());
			agentPromoteMapper.deleteByMainId(id.toString());
			withholdingTaxMapper.deleteByMainId(id.toString());
			agentMapper.deleteById(id);
		}
	}
	
}
